import java.util.Scanner;

/**
 * @author yexiebao
 * @date 2025/5/15
 */
public class DivisionOfLand {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        int[][] array = new int[n][m];
        for(int i = 0;i<n;i++){
            for(int j = 0;j<m;j++){
                array[i][j] = scanner.nextInt();
            }
        }
        //1.计算总和
        int sum = 0;
        for (int i = 0;i<n;i++){
            for (int j = 0;j<m;j++){
                sum  += array[i][j];
            }
        }
        //2.计算横向
        int[] horizontal = new int[n];
        for (int i = 0;i<n;i++){
            for (int j = 0;j<m;j++){
                horizontal[i] += array[i][j];
            }
        }
        //3.计算纵向
        int[] vertical = new int[m];
        for (int i = 0;i<m;i++){
            for (int j = 0;j<n;j++){
                vertical[i] += array[j][i];
            }
        }
        //4.定义最小值
        int min = Integer.MAX_VALUE;
        for(int i = 0;i<n;i++){
            if(sum-2*horizontal[i]<min){
                min = sum-2*horizontal[i];
            }
        }
        for(int i = 0;i<m;i++){
            if(sum-2*vertical[i]<min){
                min = sum-2*vertical[i];
            }
        }
        System.out.println(min);
        scanner.close();
    }
}